package com.sailorj.medical.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.sailorj.medical.domain.medical.Medical;
import com.sailorj.medical.exception.DbException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MedicalDao extends GenericDao<Medical> {
	private static final Logger LOG = LogManager.getLogger(MedicalDao.class);
	@Override
	protected Medical handle(ResultSet rs) throws SQLException {
		Medical entity = null;
		try {
			entity = new Medical();
			entity.setJgbm(rs.getString("jgbm"));
			entity.setZzjgbm(rs.getString("zzjgbm"));
			entity.setJgmc(rs.getString("jgmc"));
			entity.setDqbm(rs.getString("dqbm"));
			entity.setAreacode(rs.getString("areacode"));
			entity.setLsgx(rs.getString("lsgx"));
			entity.setJgjb(rs.getString("jgjb"));
			entity.setSbddlx(rs.getString("sbddlx"));
			entity.setPzddlx(rs.getString("pzddlx"));
			entity.setSsjjlx(rs.getString("ssjjlx"));
			entity.setWsjgdl(rs.getString("wsjgdl"));
			entity.setWsjgxl(rs.getString("wsjgxl"));
			entity.setZgdw(rs.getString("zgdw"));
			entity.setKysj(rs.getString("kysj"));
			entity.setFrdb(rs.getString("frdb"));
			entity.setZczj(rs.getDouble("zczj"));
			return entity;
		} catch (Exception e) {
			e.printStackTrace();
			throw new SQLException("结果集转换为对象失败:" + e.getMessage(), e);
		}

	}

	public List<Medical> findByKeyValue(String key, String value) throws DbException {
		try {
			String sqlSB = "";
			StringBuffer sb = new StringBuffer(1024);
			if (key != null && value != null) {
				sqlSB = sb.append(" and " + key + "='" + value + "'").toString();
			}
			String sql = "select * from t_medical where 1=1 " + sqlSB + "";

			Object[] params = {};

			return super.queryOjects(sql, params);

		} catch (SQLException e) {
			throw new DbException("慢性病证信息查询失败!", e);
		}
	}

}
